package com.onlyoffice.demo.findproblem.controller;

import com.onlyoffice.demo.findproblem.domain.GameLevel;
import com.onlyoffice.demo.findproblem.service.GameService;
import com.onlyoffice.demo.onlyoffice.domain.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/admin")
@RequiredArgsConstructor
public class AdminController {
    private final GameService gameService;

    /**
     * 创建关卡
     *
     * @param levelDTO 关卡信息
     * @return 结果
     */
    @PostMapping("/level")
    public R<GameLevel> createLevel(@RequestBody GameLevel levelDTO) {
        return R.ok(gameService.createLevel(levelDTO));
    }

    /**
     * 获取关卡详情（含错误点坐标）
     *
     * @param id 关卡Id
     * @return 关卡详情（含错误点坐标）
     */
    @GetMapping("/level/{id}")
    public R<GameLevel> getLevelDetail(@PathVariable Long id) {
        return R.ok(gameService.getLevelWithSpots(id));
    }

    /**
     * 更新关卡
     *
     * @param id       关卡Id
     * @param levelDTO 关卡信息
     * @return 结果
     */
    @PutMapping("/level/{id}")
    public R<GameLevel> updateLevel(@PathVariable Long id, @RequestBody GameLevel levelDTO) {
        return R.ok(gameService.updateLevel(id, levelDTO));
    }

    /**
     * 上传图片
     *
     * @param file 图片
     * @return 结果
     */
    @PostMapping("/upload-image")
    public R<String> uploadImage(@RequestParam("file") MultipartFile file) {
        return R.ok(gameService.uploadImage(file));
    }
}
